package com.kedacom.freedomLabel.view.activity.printer;

import android.content.Intent;

import com.kedacom.freedomLabel.R;
import com.kedacom.freedomLabel.base.BaseSettingActivity;
import com.kedacom.freedomLabel.base.BaseViewModel;
import com.kedacom.freedomLabel.model.bean.SettingItem;
import com.kedacom.lego.annotation.ContentView;
import com.kedacom.lego.annotation.ViewModel;


/**
 * Author：李程
 * CreateTime：2019/12/8 16:47
 * E-mail：licheng@kedacom.com
 * Describe：
 */
@ContentView(R.layout.base_setting_function)
@ViewModel(BaseViewModel.class)
public class LabelMainActivity extends BaseSettingActivity {

    @Override
    protected Intent getResultIntent() {
        return null;
    }

    @Override
    protected void setItemClickListener() {
        mAdapter.setOnItemClickListener((adapter, view, position) -> {
            beep();
            if (position == mData.size() - 1) {
                finish();
                return;
            }
            SettingItem function = mData.get(position);
            boolean needPassword = function.isPassword();
            if (needPassword) {
                openKeyInputDialog(position, this::checkKey);
            } else {
                checkKey(position, null);
            }
        });
    }

    private void checkKey(int position, String key) {
        switch (position) {
            case 0:
                if (key == null || key.equals(KEY)) {
                    Intent intent = new Intent(this, LabelSelectActivity.class);
                    startActivity(intent);
                } else {
                    showToast(getString(R.string.error_password), TOAST_ERROR);
                }
                break;
            case 1:
                if (key == null || key.equals(KEY)) {
                    Intent intent = new Intent(this, PrinterSettingActivity.class);
                    startActivity(intent);
                } else {
                    showToast(getString(R.string.error_password), TOAST_ERROR);
                }
                break;
            default:
                showToast(getString(R.string.not_open), TOAST_WARNING);
                break;
        }
    }

    @Override
    protected void initData() {
        mData.add(new SettingItem("标签模板", false));
        mData.add(new SettingItem("打印机配置", false));
        mData.add(new SettingItem(getString(R.string.manage_back), false));
    }

    @Override
    protected void setBarTitle() {
        mBinding.baseSettingTitle.setText("标签模板");
    }
}